<!-- 我的收藏 -->
<script setup lang="ts">
import { getBookInfo } from '@/api/getAxios';
import { Toast, showSuccessToast } from 'vant';
import { ref } from 'vue';

const data = defineProps({
    data: String
})
const showBook = ref(true)
const showBottom = ref(false)
const bookitem = ref()
getBookInfo(<any>(data.data)).then((res) => {
    bookitem.value = res.data.data
})
const removeTip = function () {
    let data = JSON.parse(<any>localStorage.getItem("collect"))
    data.splice(data.findIndex((val: any) => val == bookitem.value.id), 1)
    localStorage.setItem("collect", JSON.stringify(data))
    showBottom.value = false
    showBook.value = false
    showSuccessToast('取消成功');
}
</script>
<template>
    <div class="main" v-if="showBook">
        <div v-if="bookitem" class="item" @click="$router.push({ path: '/BookInfo', query: { storyId: bookitem.id } })">
            <p><img :src="bookitem.cover" alt=""></p>
            <div>
                <p>{{ bookitem.name }}<button @click.stop="showBottom = true"><img src="../assets/img/icons8-删除.gif"
                            alt=""></button></p>
                <p>{{ bookitem.authorName }}</p>
                <p>{{ bookitem.type }}</p>
                <p>更新至：{{ bookitem.latestChapter }}</p>
            </div>
        </div>
        <van-popup v-model:show="showBottom" position="bottom" :style="{ height: '30%' }">
            <p>😭</p>
            <p>是否取消收藏？</p>
            <button @click="removeTip">帮我移除</button>
        </van-popup>
    </div>
</template>

<style scoped lang='less'>
.item {
    margin: 10px 0;
    display: flex;
    background-color: white;
    border-radius: 8px;
    padding: 10px;
    transition: all 0.2s;

    &:active {
        background-color: whitesmoke;
    }

    >p:nth-child(1) {
        min-width: 26%;
        width: 26%;
        border-radius: 8px;
        overflow: hidden;
        margin-right: 10px;

        img {
            width: 100%;
            border-radius: 8px;
        }
    }

    div {
        display: flex;
        flex-direction: column;
        justify-content: space-around;
        width: 100%;
        position: relative;

        p:nth-child(1) {
            font-size: 1rem;
            color: black;
            width: 85%;
            text-overflow: ellipsis;
            overflow: hidden;
            word-break: break-all;
            white-space: nowrap;
        }

        p {
            font-size: .9rem;
            color: #605f5f;
        }

        p:last-child {
            font-size: .85rem;
        }

        button {
            background-color: white;
            border: 0;
            width: 34px;
            position: absolute;
            right: 0;
            top: 2px;

            img {
                width: 100%;
            }
        }
    }
}

.van-popup {
    padding: 10px;
    text-align: center;
    font-size: 1.1rem;
    display: flex;
    flex-direction: column;
    justify-content: space-around;

    p:nth-child(1) {
        font-size: 3rem;
    }

    button {
        width: 52%;
        border: 0;
        margin: 0 auto;
        padding: 8px 0;
        border-radius: 8px;
        background-color: var(--mcolor);
        color: whitesmoke;
        transition: all 0.2s;
        font-size: .9rem;

        &:active {
            opacity: 0.8;
        }
    }
}
</style>